package services

import (
	"context"
	db "dhuviewer/db_query"
	"fmt"

	"github.com/google/uuid"
)

func CreateSub(uid uuid.UUID) error {
	_, err := queries.CreateSub(context.Background(), db.CreateSubParams{
		Uid:     uid,
		Sublist: []uuid.UUID{},
	})
	return err
}

func Add2Sub(uid uuid.UUID, extraUsr uuid.UUID) error {
	err := queries.AddSubList(context.Background(), db.AddSubListParams{
		Uid:         uid,
		ArrayAppend: extraUsr,
	})
	return err
}

func DelOneSub(uid uuid.UUID, targetUsr uuid.UUID) error {
	err := queries.DeleteSubOne(context.Background(), db.DeleteSubOneParams{
		Uid:         uid,
		ArrayRemove: targetUsr,
	})
	return err
}

func ListSub(uid uuid.UUID) (db.Sub, error) {
	res, err := queries.GetSubs(context.Background(), uid)
	if err != nil {
		return db.Sub{}, err
	}
	return res, err
}

func ListSubInfo(uid uuid.UUID) ([]db.Socail, error) {
	res, err := queries.SubListSocailInfo(context.Background(), uid)
	if err != nil {
		return nil, err
	}
	return res, err
}

func ListSubGallery(uid uuid.UUID) ([]db.Gallery, error) {
	res, err := queries.SubGallery(context.Background(), uid)
	if err != nil {
		fmt.Println(err)
		return nil, err
	}
	return res, err
}
